<template>
  <div class="app-container">
    <div class="filter-container" style="padding-bottom:20px;">
      <el-input v-model="listQuery.name" placeholder="名称 封装 项目 产品" style="width: 400px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-date-picker
        v-model="listQuery.datetimeStart"
        type="datetime"
        placeholder="选择日期时间">
      </el-date-picker>
      <span class="demonstration">-</span>
      <el-date-picker
        v-model="listQuery.datetimeEnd"
        type="datetime"
        placeholder="选择日期时间">
      </el-date-picker>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-document">
        导出excel
      </el-button>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="orders"
      fit
      highlight-current-row
      style="width: 100%;"
      >
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="申请时间" width="200">
        <template slot-scope="scope">
          <span>{{ scope.row.created_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单号" width="310" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.sn }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提交者" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.user }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.note }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="110" align="center">
        <template slot-scope="{row}">
          <el-tag :type="row.status | statusFilter">
            {{ row.status }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="200">
        <template slot-scope="scope">
          <el-button @click="handleInfo(scope.row)" type="text" size="small">详情</el-button>
          <el-button @click="handleOutStock(scope.row)" type="text" size="small">完成出库</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>


<script>
import { userList } from '@/api/user'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'Permission',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableKey: 0,
      list: null,
      listLoading: true,
      total: 10,
      listQuery: {
        name: null,
        page: 1,
        limit: 20,
        datetimeStart: '',
        datetimeEnd: ''
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      userList(this.listQuery).then(response => {
        this.listLoading = false
        this.list = response.data
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.fetchData()
    }
  }
}
</script>
